<template>
    <el-dialog
        v-model="userDeleteDialogVisible"
        title="删除用户"
        width="20%"
        align-center
        :show-close="false"
        :close-on-click-modal="false"
    >
        是否确定删除？
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancelDialog()">取 消</el-button>
                <el-button type="primary" :loading="deleteLoading" @click="submitDialog()">
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script>
import {userInfoDelete, userInfoQuery} from "@/request/user";
import {ElNotification} from "element-plus";

export default {
    name: "UserDeleteDialog",
    props: ['userDataForm'],
    data() {
        return {
            deleteLoading: false
        }
    },
    computed: {
        userDeleteDialogVisible() {
            return this.$store.state.userDeleteDialogVisible;
        },
        userSearchData() {
            return this.$store.state.userSearchData;
        }
    },
    methods: {
        cancelDialog() {
            this.$store.commit('changeUserDeleteDialogVisible', false);
        },
        submitDialog() {
            this.deleteLoading = true
            userInfoDelete(this.userDataForm).then(res => {
                if (res.code === '200') {
                    ElNotification({
                        title: 'Success',
                        message: res.message,
                        type: 'success'
                    });
                    userInfoQuery(this.userSearchData).then(res => {
                        this.$store.commit('changeUserDataList', res.data)
                    })
                    this.$store.commit('changeUserDeleteDialogVisible', false);
                }
                this.deleteLoading = false
            }).catch(res => {
                this.deleteLoading = false
            })
        }
    }
}
</script>

<style scoped>

</style>